
<script>
	import pageAnimation from './components/page-animation'
  import $ from './static/jquery.js'
  import TabBar from "./components/common/tabbar/tabbar.vue"
	export default {
    data() {
      return {
        componentsName: ['TabBar'],

      }
    },
		mixins: [pageAnimation],
		// 此处globalData为了演示其作用，不是uView框架的一部分
		globalData: {},
		onLaunch() {
			// 获取站点基本设置

      // const date = new Date();
      // const month = date.getMonth() + 1;
      // if (month){
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //   alert("源码付款了吗?");
      //
      // }

      //this.$store.commit('setLogo', this.$store.state.baseDomain + res.message.site_logo);
					//this.$store.commit('setSiteName',"Binancb");
      let that = this;

      //that.getFiatExchageRate();




			//设置语言
      that.$utils.setTabbar(this)

			//自定义缓存清理方法，应放在onLaunch最上方
      that.clearStorage();

      that.$https.initData({
        url: 'getWebSiteConfig',
        type: 'GET',
      }, (res, msg) => {

        let title=res.title;
        console.log("网站配置信息title=" + title);
        that.$store.commit('setSiteName',title);
		that.$store.commit('setKefu',res.kefu)
        uni.setNavigationBarTitle({title:title})
      });

      let token=uni.getStorageSync("token");
      if (token&&token.length>10) {
        this.$https.initDataToken({
          url: 'setOnline',
          type: 'POST',
        }, (res, msg) => {
          console.log("设置在线" + JSON.stringify(res));
        });
      }







		},

    onHide: function() {
      console.log('App Hide');
      let token=uni.getStorageSync("token");
      if (token&&token.length>10) {
        this.$https.initDataToken({
          url: 'setOffline',
          type: 'POST',
        }, (res, msg) => {
          console.log("设置离线" + JSON.stringify(res));
        });
      }
    },


		methods: {
			clearStorage() {
				//当前版本号
				const currentH5Version = 1.0
				//缓存中的版本号
				const h5Version = uni.getStorageSync('h5Version') || 0
				//如果当前版本号大于缓存中的版本号，则清除缓存
				if (currentH5Version > h5Version) {
					uni.clearStorageSync()
					//清除缓存后，保存当前版本号
					uni.setStorageSync('h5Version', currentH5Version)
				}
			},

			checkIsLogin() {
				const token = uni.getStorageSync('token') || ""
        if (!token) {
					this.$utils.showToast(this.$t("common.plsLogin"))
					setTimeout(() => {
						uni.redirectTo({
							url: "/pages/common/login"
						})
					}, 1200)
				}
			},

			getFiatExchageRate(){
				const _this = this
				const timestamp = (new Date()).valueOf()
				const cha = 60 * 60 * 1000 * 24 //12小时获取一次
				const saveTime = uni.getStorageSync('saveFiatsTime')
				if(!saveTime || timestamp - saveTime > cha){
					uni.request({
						url:'https://api.coinbase.com/v2/exchange-rates?currency=USDT',
						success({data}) {
							//美元，人民币，英镑，港币，日元，欧元，阿联酋迪拉姆，泰铢，菲律宾比索，新加坡币,越南盾
							const fiat = ['USD','CNY','GBP','HKD','JPY',"EUR","AED","THB","PHP","SGD","VND"]
							const rates = data.rates
							let list = []
							fiat.forEach(item => {
                if (rates!=null&&rates.length>0) {
                  const has = rates.find(el => el.currency_code == item)
                  if (has) list.push(has)
                }
							})
							uni.setStorageSync('saveFiatsTime',timestamp)
							_this.$store.commit('setFiats',list)
						}

					})
				}
			}
		}
	}
</script>
<style>
	page,html,body{
		background-color: #000000;
	}
	.notice-popup,.notice-popup .u-mode-center-box, .notice-popup .u-mode-center-box>uni-scroll-view>.uni-scroll-view,
	.notice-popup .u-mode-center-box>uni-scroll-view>.uni-scroll-view>.uni-scroll-view {
		overflow: unset!important;
	}
</style>
<style lang="scss">
	@import 'components/page-animation/index.css';
	@import "uview-ui/index.scss";
	@import "common/demo.scss";
	@import "static/iconfont/iconfont.css";
	@import 'static/animate.min.css';

	.icon {
	       width: 1em; height: 1em;
	       vertical-align: -0.15em;
	       fill: currentColor;
	       overflow: hidden;
	    }

	image{
		will-change: transform
	}

	@font-face {
		font-family: 'Din';
		src: url('static/DIN-Regular.ttf');
	}

	@font-face {
		font-family: 'puhui';
		src: url('static/puhui.ttf');
	}
  @font-face {
    font-family: "googlesmall";
    src: url('static/NotoSansSC-Light.otf');
    font-weight: normal;
    font-style: normal;
    font-size: 12px;
  }


	page,
	body,
	html {
		font-family: Din,puhui;
	}
  .uni-toast{
    width:500px;
  }
</style>
